package com.dongdong.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.dongdong.data.Page;
import com.dongdong.data.Result;
import com.dongdong.em.ResultEmnu;
import com.dongdong.pojo.TbSeller;
import com.dongdong.service.SellerService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("sellerController")
public class SellerController {
    @Reference
    private SellerService sellerService;
    @RequestMapping("toSeller")
    public String toSeller(){
        return "admin/seller";
    }
    @RequestMapping("sellerList")
    @ResponseBody
    public Result sellerList(TbSeller tbSeller){
        List<TbSeller> sellerPage =  sellerService.selectInfo(tbSeller);
        return Result.respone(ResultEmnu.SUCCESS).setData(sellerPage);
    }
    @RequestMapping("getById/{sellerId}")
    @ResponseBody
    public Result getById(@PathVariable("sellerId")String sellerId , Model model){
        try{
            TbSeller seller = sellerService.selectBysellerId(sellerId);
            model.addAttribute("seller",seller);
            return Result.respone(ResultEmnu.SUCCESS).setData(seller);
        }catch (Exception e){
            e.printStackTrace();
            return Result.respone(ResultEmnu.ERROR);
        }
    }
    @RequestMapping("upStatus")
    @ResponseBody
    public Result upStatus(TbSeller tbSeller){
         int i = sellerService.updateStatus(tbSeller);
         if (i > 0){
             return Result.respone(ResultEmnu.SUCCESS);
         }else {
             return Result.respone(ResultEmnu.ERROR);
         }
    }
}
